from data_processing.data_conversion import DataProcessing
from data_processing.decompression import csv_file_name
from score.GKscore import GKScore
from score.CBscore import CBScore
from score.CMscore import CMScore
from score.STscore import STScore
from score.integral import Integral


class UserOperation:
    def __init__(self, time, target_dir, score_file):
        self.time = time
        self.target_dir = target_dir
        self.score_file = score_file
        self.game = 0

    def operation(self):
        csv_list = csv_file_name(self.target_dir)
        table_score = list()
        for a in csv_list:
            self.game += 1
            every_game_table = list()
            list_dic = DataProcessing().data_import(self.target_dir + a)
            for b in list_dic:
                if b['Positions'] == 'GK':
                    GK = GKScore(b).score()
                    table_score.append(GK)
                    every_game_table.append(GK)
                elif b['Positions'] == 'CB':
                    CB = CBScore(b).score()
                    table_score.append(CB)
                    every_game_table.append(CB)
                elif b['Positions'] == 'CM':
                    CM = CMScore(b).score()
                    table_score.append(CM)
                    every_game_table.append(CM)
                elif b['Positions'] == 'ST':
                    ST = STScore(b).score()
                    table_score.append(ST)
                    every_game_table.append(ST)
            head_list = list(table_score[0].keys())
            score_file = "D:\pyitem\soccer\data\\score(every_game)\\" + self.time + "score" + str(self.game) + ".xlsx"
            DataProcessing().merge_export(table_score, head_list, score_file, False)
        head_list = list(table_score[0].keys())
        # DataProcessing().merge_export(table_score, head_list, self.score_file)


if __name__ == "__main__":
    a = ['1002', '1003', '1004', '1005', '1006', '1007', '1008', '1010', '1011']
    for a in a:
        UserOperation(a, "D:\pyitem\soccer\data\\" + a + "\\", "D:\pyitem\soccer\data\\score(every_day)\\" + a + "score.xlsx").operation()
